package com.newtouch.bxzs.database.synchronize.batch.writer;

import com.newtouch.bxzs.database.synchronize.mapper.achievement.AchievementMapper;
import com.newtouch.bxzs.database.synchronize.mapper.achievement.AchievementPolicyMapper;
import com.newtouch.bxzs.database.synchronize.model.achievement.AchievementPolicyVO;
import com.newtouch.bxzs.database.synchronize.model.achievement.AchievementVO;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 业绩同步入库
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 10:09</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
@SuppressWarnings("unchecked")
public class WriterAchievement {

	@Autowired
	private AchievementMapper achievementMapper;

	@Autowired
	private AchievementPolicyMapper achievementPolicyMapper;

	/**
	 * 同步个人业绩数据至数据库
	 * 
	 * @return ItemWriter
	 */
	public ItemWriter<AchievementVO> addAchievement() {
		return list -> achievementMapper.addAchievement((List<AchievementVO>) list, new Date());
	}

	/**
	 * 同步个人业绩数据明细至数据库
	 * 
	 * @return ItemWriter
	 */
	public ItemWriter<AchievementPolicyVO> addAchievementPolicy() {
		return list -> achievementPolicyMapper.addAchievementPolicy((List<AchievementPolicyVO>) list, new Date());
	}
}
